﻿using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Entities;

namespace Volo.Abp.Domain.Repositories;

public static class LwzxReadOnlyRepositoryExtensions
{
    /// <summary>
    /// 根据ID列表获取
    /// </summary>
    public static async Task<List<TEntity>> GetListAsync<TEntity, TKey>(this IReadOnlyRepository<TEntity, TKey> repo, IEnumerable<TKey> ids, bool includeDetails = false,
        CancellationToken cancellationToken = default) where TEntity : class, IEntity<TKey>
    {
        var query = await (includeDetails ? repo.WithDetailsAsync() : repo.GetQueryableAsync());
        return await query.Where(x => ids.Contains(x.Id))
            .ToListAsync(cancellationToken);
    }
}
